import baseToast from "./baseToast"
function server({url, method='get', data=''}) {
  wx.showLoading({
    title: '拼命加载中...'
  })
  return new Promise((resolve, reject) => {
    wx.request({
      url: 'https://www.uinav.com/api/public/v1' + url,
      method: method,
      data: data,
      success:(res) => {
        let { message, meta } = res.data
        if(meta.status === 200) {
          resolve(message)
        } else {
          baseToast(meta.msg)
        }
      },
      fail:(err) => {
        reject(err)
      },
      complete() {
        wx.hideLoading()
      }
    })
  })
}

export default server